#include "CreditState.h"
#include "../DeadlyShadowsLastHope/Game.h"
#include "MainMenuState.h"
#include "OptionsState.h"
//#include "GameplayState.h"

CCreditState* CCreditState::GetInstance(void)
{
	static CCreditState s_Instance;
	return &s_Instance;
}

CCreditState::CCreditState(void)
{
	m_pD3D	= nullptr;	//device
	m_pTM	= nullptr;	//texture
	m_pDI	= nullptr;	//input
	m_pOM	= nullptr;	//object

	m_nMove = m_nScreenHeight ;
	m_nScreenWidth = CGame::GetInstance()->GetWidth();
	m_nScreenHeight = CGame::GetInstance()->GetHeight();
	m_nBackGroundImageID = -1;
	m_fFPSTimer = 0.0f;
	m_unFrames = 0;
	m_unFPS = 0;
}

CCreditState::~CCreditState(void)
{
}

void CCreditState::Enter(void)
{
	//setup the state
	m_pD3D	= CSGD_Direct3D::GetInstance();
	m_pTM	= CSGD_TextureManager::GetInstance();
	m_pDI	= CSGD_DirectInput::GetInstance();
	m_pOM	= CObjectManager::GetInstance();
	m_pFont.Load("../resources/XML/DeadlyShadowsFont.xml");
	m_nMove = m_nScreenHeight + 10;
	//m_nBackGroundImageID = m_pTM->LoadTexture(	_T("resource/graphics/..INSERT IMAGE HERE..."), D3DCOLOR_XRGB(0, 0, 0) );
}

void CCreditState::Update(float fElapsedTime)
{
	m_fFPSTimer += fElapsedTime * 40;
	
	if( m_fFPSTimer > 1.0f )
	{
		m_unFPS = m_unFrames;
		m_unFrames = 0;
		m_fFPSTimer = 0.0f;
		m_nMove -= 1;
	}

	if (m_nMove < -500)
	{
		m_nMove = m_nScreenHeight + 10;
	}
}

void CCreditState::Exit(void)
{
	if( m_pOM != nullptr )
	{
		m_pOM->RemoveEVERYTHING();
		m_pOM = nullptr;
		CObjectManager::DeleteInstance();
	}
	if( m_nBackGroundImageID != -1 )
	{
		m_pTM->UnloadTexture( m_nBackGroundImageID );
		m_nBackGroundImageID = -1;
	}
}

void CCreditState::Render(void)
{
	//m_pTM->Draw(m_nBackGroundImageID, (int)(m_nScreenWidth * 0.5f) - m_nScreenWidth, ((int)(m_nScreenHeight * 0.5f) - m_nScreenHeight) + 130, 1.0f, 1.0f, nullptr, 0, 0, 0); 
	m_pD3D->GetSprite()->Flush();
	m_pFont.Print("Game Credits", (int)(m_nScreenWidth * 0.5f) - 200, m_nMove-40, 1.5f, D3DXCOLOR(128,128,128,255));
	
	m_pFont.Print("Game Designer...Mattew Berry", (int)(m_nScreenWidth * 0.5f) - 200, m_nMove, 1.5f, D3DXCOLOR(128,128,128,255));
	m_pFont.Print("Game Designer...Corey Morehead", (int)(m_nScreenWidth * 0.5f) -200, m_nMove+40, 1.5f, D3DXCOLOR(128,128,128,255));
	m_pFont.Print("Game Designer...Michael Robinson", (int)(m_nScreenWidth * 0.5f) -200, m_nMove+80, 1.5f, D3DXCOLOR(128,128,128,255));
	m_pFont.Print("Game Designer...Jon Stumpfel", (int)(m_nScreenWidth * 0.5f) -200, m_nMove+120, 1.5f, D3DXCOLOR(128,128,128,255));
	
	m_pFont.Print("Game Developer...Mattew Berry", (int)(m_nScreenWidth * 0.5f) - 200, m_nMove+180, 1.5f, D3DXCOLOR(128,128,128,255));
	m_pFont.Print("Game Developer...Corey Morehead", (int)(m_nScreenWidth * 0.5f) -200, m_nMove+220, 1.5f, D3DXCOLOR(128,128,128,255));
	m_pFont.Print("Game Developer...Michael Robinson", (int)(m_nScreenWidth * 0.5f) -200, m_nMove+260, 1.5f, D3DXCOLOR(128,128,128,255));

	m_pFont.Print("Game Arist...Maher Sagrillo", (int)(m_nScreenWidth * 0.5f) -200, m_nMove+340, 1.5f, D3DXCOLOR(128,128,128,255));

	m_pFont.Print("FULL SAIL UNIVERSITY", (int)(m_nScreenWidth * 0.5f)-350, m_nMove+400, 2.5f, D3DXCOLOR(128,1128,128,255));
}

bool CCreditState::Input(void)
{
	if (m_pDI->KeyPressed(DIK_ESCAPE))
	{
		CGame::GetInstance()->AddState(COptionsState::GetInstance());
		CGame::GetInstance()->RemoveState(this);
	}
	return true;
}
